package org.hhchat.leetcode.array;

import java.util.Arrays;

public class code189_easy {

    static class Solution {
        public void rotate(int[] nums, int k) {
            k %= nums.length;
            int[] nums2 = new int[k];
            for(int i=nums.length-k,j=0;i<nums.length;i++,j++) {
                nums2[j] = nums[i];
            }
            for(int i=nums.length-1;i>=k;i--) {
                nums[i] = nums[i-k];
            }
            for(int i=0;i<k;i++) {
                nums[i] = nums2[i];
            }
        }
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        int nums[] = {1, 2, 3, 4, 5, 6, 7};
        solution.rotate(nums, 3);
        System.out.println(Arrays.toString(nums));
    }
}
